﻿/*
 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

#ifndef BURNDLG3X_H
#define BURNDLG3X_H

#include "BurnDlg.h"
#include "ui_BurnDlg3X.h"
#include "MultipleBurnDlg.h"

namespace BurnDlg {

class BurnDlg3X : public BurnDlg {
    Q_OBJECT
public:
    explicit BurnDlg3X(ChipType chipType, QWidget *pParent = nullptr);
    ~BurnDlg3X() override;

    void InitBurnCtrl() override;
    void UpdateList() override;
protected slots:
    void SlotSaveConfig();
    void SlotImportConfig();
    virtual void SlotBnClickedButtonSelectfile() override;
    void SlotBnClickedButtonStartburn() override;
    void SlotCbnSetfocusComboCom() const;
    void SlotInsertPlainText(const QString &editStr) override;
    void SlotOpenComFail();
    void SlotBurnFileFinish();
    void SlotBurnFileFailed();
    void SlotSetProgress(double pos) const;
    void SlotConfigTimerTimeOut();
    void SlotShowQMessageBox(QString str);
    void SlotShowMenuSettings() override;
    void SlotBnClickedMultipleBurn();
    void SlotMultipleBurnDlgClose();
    void SlotSettingSuccess() override;
    void SlotBnClickedSelectTarget();
    void SlotBnClickedExport();
    void SlotExportFail();
    void SlotExportSuccess();
    void SlotBnClickedEraseAll();
    void SlotEraseFail() const;
    void SlotEraseSuccess() const;
    void SlotCreateNewFwpkgFile();
    void SlotSaveSpiltFwpkgFile();

protected:
    void changeEvent(QEvent* event) override;
    bool ConfigComPort() override;
    void UpdateList(BIN_INFO_ARRAY &info) const;
    void FillParamAndShow(const QMap<int, BIN_INFO> &info);
    void GetCmdInfoArray(QMap<int, BIN_INFO> &infoArray);

private:
    void SaveDlgConfig();
    void SavedComConfig2File(const QString &path) const;
    void SavedWinInfoConfig2File(const QString &path) const;
    void SavedBinInfoConfig2File(const QString &path) const;
    void LoadDlgConfig() const;
    void LoadComConfigFromFile(const QString &path) const;
    void LoadFileConfigFromFile(const QString &path) const;
    void InitConnect();
    void AnalyseBinFile(QString filePath);
    void AnalyseBinFileSub(QMap<int, BIN_INFO> &mapBinInfo, QMap<int, bool> &mapCheck,
                           QMap<int, BIN_INFO> &mapLastBinInfo, QMap<int, bool> &mapLastBinCheck) const;
    void UpdateVersion(const QString &version) const;
    void UpdateCmd();
    void GetBinInforArray(QMap<int, BIN_INFO> &infoArray, int row);
    void InitTableView() const;
    void PriorityBurn(const BIN_INFO_ARRAY &infoArray, QMap<int, BIN_INFO> &checkBinInfo, int &i) const;
    void RemoveTempDir() const;
    void InitMenus();
    void contextMenuEvent(QContextMenuEvent *event) override;

private:
    Ui::BurnDlg3X *ui;
    QAction *actSettings;
    QAction *actImportConfig;
    QAction *actSaveConfig;
    QMap<int, BIN_INFO> burnInfo;
    QTimer *configTimer;
    QAction *actChangeChip;
    QAction *actAbout;
    bool isMultipleBurnOpen;
    MultipleBurnDlg *multipleBurnDlg;
    QMutex *mutex;
    QMenu *tableViewMenu;
};

}
#endif // BURNDLG3X_H
